Improve insertOrUpdate() API consistency across database adapters#992
Merged
Improve insertOrUpdate() API consistency across database adapters#992
Conversation
markstory
reviewed
Jan 12, 2026
Comment on lines
+811
to
+819
| * - **MySQL**: Uses `ON DUPLICATE KEY UPDATE`. The `$conflictColumns` parameter is | ||
| * ignored because MySQL automatically applies the update to all unique constraint | ||
| * violations. Passing `$conflictColumns` will trigger a deprecation warning. | ||
| * | ||
| * - **PostgreSQL/SQLite**: Uses `ON CONFLICT (...) DO UPDATE SET`. The `$conflictColumns` | ||
| * parameter is required and must specify the columns that have a unique constraint. | ||
| * A RuntimeException will be thrown if this parameter is empty. | ||
| * | ||
| * - **SQL Server**: Not currently supported. Use separate insert/update logic. |
Member
There was a problem hiding this comment.
Should this also be in the docs? There are a lot of caveats to using this method.
Member
Author
There was a problem hiding this comment.
Added docs for insertOrSkip() and insertOrUpdate() in docs/en/seeding.rst with the database-specific caveats in a warning block.
Member
Author
|
Changed |
- Add deprecation warning for MySQL when conflictColumns is passed (ignored) - Add RuntimeException for PostgreSQL/SQLite when conflictColumns is missing - Document database-specific behavior in Table.php and SeedInterface.php - Add tests for PostgreSQL and SQLite conflict column validation
Since insertOrUpdate is a new feature, using deprecationWarning() doesn't make semantic sense. Switch to trigger_error() with E_USER_WARNING to alert developers that the parameter is ignored on MySQL without implying the feature will be removed.
Documents the insert modes with database-specific behavior caveats, particularly the MySQL vs PostgreSQL/SQLite differences for upsert.
69f50b5 to
ca4a1d4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses API consistency issues with
insertOrUpdate()across different database adapters:MySQL: The
$conflictColumnsparameter is ignored because MySQL'sON DUPLICATE KEY UPDATEautomatically applies to all unique constraints. Now triggers a deprecation warning when passed.PostgreSQL/SQLite: The
$conflictColumnsparameter is required. Now throws aRuntimeExceptionwith a clear message if missing or empty.Documentation: Added comprehensive docblocks explaining the database-specific behavior in
Table.phpandSeedInterface.php.Changes
AbstractAdapter::getUpsertClause()when$conflictColumnsis passed (MySQL)PostgresAdapter::getConflictClause()when$conflictColumnsis missingSqliteAdapter::getUpsertClause()when$conflictColumnsis missingTable::insertOrUpdate()andSeedInterface::insertOrUpdate()Test plan